package tcp;

import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class chatserver {
	public static void main(String[] args) throws Exception{
		ServerSocket svrSK=null;
		try{
			//0.tao cong lang nghe
			svrSK=new ServerSocket(8080);
			System.out.println("listenning...client");
			//2.1 chap nhan ket noi
			Socket soc=svrSK.accept();
			//2.2 xu ly request
			Scanner input=new Scanner(soc.getInputStream());
			System.out.println("Client: ");
			String request=input.nextLine();
			//3 response cho client
			String response="From server:"+request.toUpperCase();
			PrintWriter out=new PrintWriter(soc.getOutputStream(),true);
			out.println(response);
			input.close();
		}
		catch(Exception e){
			e.getStackTrace();
		}
		finally{
			if(svrSK!=null)svrSK.close();
		}
	}
}
